package com.example.lenovo.mywechat;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageButton btn_weChat;
    private ImageButton btn_contact;
    private ImageButton btn_find;
    private ImageButton btn_me;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_weChat=findViewById(R.id.btn_wechat);
        btn_contact=findViewById(R.id.btn_contact);
        btn_find=findViewById(R.id.btn_find);
        btn_me=findViewById(R.id.btn_me);

        btn_weChat.setOnClickListener(this);
        btn_contact.setOnClickListener(this);
        btn_find.setOnClickListener(this);
        btn_me.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_wechat:
                selectIndex(0);
                break;
            case R.id.btn_contact:
                selectIndex(1);
                break;
            case R.id.btn_find:      
                selectIndex(2);
                break;
            case R.id.btn_me:
                selectIndex(3);
                break;
                 default:
                     Log.e("Maintivity","123");
        }
    }

    private void selectIndex(int i) {
        btnReSet();
        switch (i){
            case 0:
                btn_weChat.setImageResource(R.mipmap.tab_weixin_pressed);
                break;
            case 1:
                btn_contact.setImageResource(R.mipmap.tab_contact_pressed);
                break;
            case 2:
                btn_find.setImageResource(R.mipmap.tab_find_pressed);
                break;
            case 3:
                btn_me.setImageResource(R.mipmap.tab_setting_pressed);
                break;
                default:
                    break;
        }
    }

    private void btnReSet() {
        btn_weChat.setImageResource(R.mipmap.tab_weixin_normal);
        btn_contact.setImageResource(R.mipmap.tab_contact_normal);
        btn_find.setImageResource(R.mipmap.tab_find_normal);
        btn_me.setImageResource(R.mipmap.tab_setting_normal);
    }
}
